/*
 * @Author: lokei
 * @Date: 2022-09-08 21:38:59
 * @LastEditors: lokei
 * @LastEditTime: 2022-09-08 22:38:35
 * @Description: 
 */
package cn.lokei.coap.controller;

import com.alibaba.fastjson.JSONObject;

import cn.lokei.coap.annotation.CoapGetMapping;
import cn.lokei.coap.annotation.CoapResource;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;

@CoapResource
public class SensorController {
    
    @CoapGetMapping("temperature")
    public void get(ChannelHandlerContext ctx, DatagramPacket packet) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("temperature", "36");
        ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(
                jsonObject.toJSONString(),CharsetUtil.UTF_8), packet.sender()));
    }
}
